<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/modules/mac/LMacLayer.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00432.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">LMacLayer.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *  LMACLayer.cc</span>
<a name="l00003"></a>00003 <span class="comment"> *  LMAC for MF 2.02, omnetpp 3.4</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> *  Created by Anna Förster on 10/10/08.</span>
<a name="l00006"></a>00006 <span class="comment"> *  Copyright 2008 Universita della Svizzera Italiana. All rights reserved.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *  Converted to MiXiM by Kapourniotis Theodoros</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef LMAC_LAYER_H</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define LMAC_LAYER_H</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;MiXiMDefs.h&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;DroppedPacket.h&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;BaseMacLayer.h&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;PhyUtils.h&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;SimpleAddress.h&quot;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="keyword">class </span>LMacPkt;
<a name="l00024"></a>00024 
<a name="l00063"></a><a class="code" href="a00126.html">00063</a> <span class="keyword">class </span>MIXIM_API <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a> : <span class="keyword">public</span> <a class="code" href="a00026.html" title="A very simple MAC module template which provides de- and encapsulation of messages using the standard...">BaseMacLayer</a>
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065     <span class="keyword">private</span>:
<a name="l00068"></a>00068         <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>(<span class="keyword">const</span> <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>&amp;);
<a name="l00071"></a>00071         <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>&amp; <a class="code" href="a00026.html#aac78343ae4c96940669323e51ec09ada" title="Assignment operator is not allowed.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>&amp;);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="keyword">public</span>:
<a name="l00074"></a>00074   <a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>()
<a name="l00075"></a>00075     : <a class="code" href="a00026.html" title="A very simple MAC module template which provides de- and encapsulation of messages using the standard...">BaseMacLayer</a>()
<a name="l00076"></a>00076     , SETUP_PHASE(<span class="keyword">true</span>)
<a name="l00077"></a>00077     , slotChange()
<a name="l00078"></a>00078     , macState()
<a name="l00079"></a>00079     , radioState()
<a name="l00080"></a>00080     , slotDuration(0)
<a name="l00081"></a>00081     , controlDuration(0)
<a name="l00082"></a>00082     , mySlot(0)
<a name="l00083"></a>00083     , numSlots(0)
<a name="l00084"></a>00084     , currSlot()
<a name="l00085"></a>00085     , reservedMobileSlots(0)
<a name="l00086"></a>00086     , macQueue()
<a name="l00087"></a>00087     , queueLength(0)
<a name="l00088"></a>00088     , wakeup(NULL)
<a name="l00089"></a>00089     , timeout(NULL)
<a name="l00090"></a>00090     , sendData(NULL)
<a name="l00091"></a>00091     , initChecker(NULL)
<a name="l00092"></a>00092     , checkChannel(NULL)
<a name="l00093"></a>00093     , start_lmac(NULL)
<a name="l00094"></a>00094     , send_control(NULL)
<a name="l00095"></a>00095     , bitrate(0)
<a name="l00096"></a>00096     , droppedPacket()
<a name="l00097"></a>00097     , nicId(-1)
<a name="l00098"></a>00098     , txPower(0)
<a name="l00099"></a>00099   {}
<a name="l00101"></a>00101         <span class="keyword">virtual</span> ~<a class="code" href="a00126.html" title="Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel ...">LMacLayer</a>();
<a name="l00102"></a>00102 
<a name="l00104"></a>00104         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a61c82dc3b225eac37f7fa9936c28c2c3" title="Initialization of the module and some variables.">initialize</a>(<span class="keywordtype">int</span>);
<a name="l00105"></a>00105 
<a name="l00107"></a>00107         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00025.html#a5ab11502dbeeea89693d29841376a2f7" title="Called when the simulation has finished.">finish</a>();
<a name="l00108"></a>00108 
<a name="l00110"></a>00110         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a413375cec02b990a521b62086a02264c">handleLowerMsg</a>(cMessage*);
<a name="l00111"></a>00111 
<a name="l00113"></a>00113         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a6de2ca07018de313a7147a03e6d77bff" title="Handle messages comming from the network layer.">handleUpperMsg</a>(cMessage*);
<a name="l00114"></a>00114 
<a name="l00116"></a>00116         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#add5277c1a60dab10db40c8d9641e48c4" title="Handle self messages such as timer...">handleSelfMsg</a>(cMessage*);
<a name="l00117"></a>00117 
<a name="l00119"></a>00119         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a796d456d593dfab3188b37e506dd76a8" title="Handle control messages from lower layer.">handleLowerControl</a>(cMessage *msg);
<a name="l00120"></a>00120 
<a name="l00122"></a>00122         <span class="keyword">virtual</span> macpkt_ptr_t <a class="code" href="a00026.html#a0e1c8dad62e40f43a43c7b8a0cb71501" title="Encapsulate the NetwPkt into an MacPkt.">encapsMsg</a>(cPacket*);
<a name="l00123"></a>00123 
<a name="l00124"></a>00124     <span class="keyword">protected</span>:
<a name="l00125"></a>00125         <span class="keyword">typedef</span> std::list&lt;LMacPkt*&gt; MacQueue;
<a name="l00126"></a>00126 
<a name="l00139"></a><a class="code" href="a00126.html#a201a85e1ae744df103db6773739690ff">00139</a>         <span class="keyword">enum</span> <a class="code" href="a00126.html#a201a85e1ae744df103db6773739690ff" title="MAC states.">States</a>
<a name="l00140"></a>00140         {
<a name="l00141"></a>00141             INIT, SLEEP, CCA, WAIT_CONTROL, WAIT_DATA, SEND_CONTROL, SEND_DATA
<a name="l00142"></a>00142         };
<a name="l00143"></a>00143 
<a name="l00144"></a>00144         <span class="keyword">enum</span> TYPES
<a name="l00145"></a>00145         {
<a name="l00146"></a>00146             LMAC_CONTROL = 167,
<a name="l00147"></a>00147             LMAC_TIMEOUT = 168,
<a name="l00148"></a>00148             LMAC_WAKEUP = 169,
<a name="l00149"></a>00149             LMAC_SEND_DATA = 170,
<a name="l00150"></a>00150             LMAC_SETUP_PHASE_END = 171,
<a name="l00151"></a>00151             LMAC_CHECK_CHANNEL = 172,
<a name="l00152"></a>00152             LMAC_SOMEBODY = 173,
<a name="l00153"></a>00153             LMAC_DATA = 174,
<a name="l00154"></a>00154             LMAC_START_LMAC = 175,
<a name="l00155"></a>00155             LMAC_SEND_CONTROL = 176
<a name="l00156"></a>00156         };
<a name="l00157"></a>00157 
<a name="l00159"></a><a class="code" href="a00126.html#a04b4749559221c7d8f886e01ecc123e6">00159</a>         <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> <a class="code" href="a00126.html#a04b4749559221c7d8f886e01ecc123e6" title="dummy receiver address to indicate no pending packets in the control packet">LMAC_NO_RECEIVER</a>;
<a name="l00160"></a>00160         <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> LMAC_FREE_SLOT;
<a name="l00161"></a>00161 
<a name="l00163"></a><a class="code" href="a00126.html#a6c97a461db5cd91f55d3d924b2a184dd">00163</a>         <span class="keywordtype">bool</span> <a class="code" href="a00126.html#a6c97a461db5cd91f55d3d924b2a184dd" title="the setup phase is the beginning of the simulation, where only control packets at very small slot dur...">SETUP_PHASE</a>;
<a name="l00164"></a>00164 
<a name="l00166"></a><a class="code" href="a00126.html#aae582a227411bd299295dec277ab7ad0">00166</a>         cOutVector* <a class="code" href="a00126.html#aae582a227411bd299295dec277ab7ad0" title="indicate how often the node needs to change its slot because of collisions">slotChange</a>;
<a name="l00167"></a>00167 
<a name="l00169"></a><a class="code" href="a00126.html#a48ad85f4aaba675b8f5287ad2bdd6007">00169</a>         <a class="code" href="a00126.html#a201a85e1ae744df103db6773739690ff" title="MAC states.">States</a> <a class="code" href="a00126.html#a48ad85f4aaba675b8f5287ad2bdd6007" title="keep track of MAC state">macState</a>;
<a name="l00170"></a>00170 
<a name="l00172"></a><a class="code" href="a00126.html#a87f91fbb028f4b50115f3831f135da99">00172</a>         <a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7" title="The state of the radio of the nic.">MiximRadio::RadioState</a> <a class="code" href="a00126.html#a87f91fbb028f4b50115f3831f135da99" title="Current state of active channel (radio), set using radio, updated via BB.">radioState</a>;
<a name="l00173"></a>00173 
<a name="l00175"></a><a class="code" href="a00126.html#aadcf84520c3dec4d76236cac8fdff135">00175</a>         <span class="keywordtype">double</span> <a class="code" href="a00126.html#aadcf84520c3dec4d76236cac8fdff135" title="Duration of a slot.">slotDuration</a>;
<a name="l00177"></a><a class="code" href="a00126.html#a3bcd0ad076a7868e7d8ae0e591d46fec">00177</a>         <span class="keywordtype">double</span> <a class="code" href="a00126.html#a3bcd0ad076a7868e7d8ae0e591d46fec" title="Duration of teh control time in each slot.">controlDuration</a>;
<a name="l00179"></a><a class="code" href="a00126.html#a86d7beca6b3521cb80b44cd8c239b48d">00179</a>         <span class="keywordtype">int</span> <a class="code" href="a00126.html#a86d7beca6b3521cb80b44cd8c239b48d" title="my slot ID">mySlot</a>;
<a name="l00181"></a><a class="code" href="a00126.html#a5182c67d55642bb0789bed7222a9e36c">00181</a>         <span class="keywordtype">int</span> <a class="code" href="a00126.html#a5182c67d55642bb0789bed7222a9e36c" title="how many slots are there">numSlots</a>;
<a name="l00183"></a><a class="code" href="a00126.html#aee8d9b764a36dd71fc189cbf6ef56d6e">00183</a>         <span class="keywordtype">int</span> <a class="code" href="a00126.html#aee8d9b764a36dd71fc189cbf6ef56d6e" title="The current slot of the simulation.">currSlot</a>;
<a name="l00185"></a><a class="code" href="a00126.html#a26e2b33eae9cef9a2b578173deba9a05">00185</a>         <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> occSlotsDirect[64];
<a name="l00187"></a><a class="code" href="a00126.html#a28d9565b4b0a059ce0826e2610afb912">00187</a>         <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> occSlotsAway[64];
<a name="l00189"></a><a class="code" href="a00126.html#aa5508d9b952be702c8a4d33d63dc517c">00189</a>         <span class="keywordtype">int</span> <a class="code" href="a00126.html#aa5508d9b952be702c8a4d33d63dc517c" title="The first couple of slots are reserved for nodes with special needs to avoid changing slots for them ...">reservedMobileSlots</a>;
<a name="l00190"></a>00190 
<a name="l00193"></a><a class="code" href="a00126.html#a4d4d0764f3a0b35fce09f71fa334ede5">00193</a>         MacQueue <a class="code" href="a00126.html#a4d4d0764f3a0b35fce09f71fa334ede5" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>;
<a name="l00194"></a>00194 
<a name="l00196"></a><a class="code" href="a00126.html#aa13209c2a38ad4cb43f4c73a3283e55c">00196</a>         <span class="keywordtype">unsigned</span> <a class="code" href="a00126.html#aa13209c2a38ad4cb43f4c73a3283e55c" title="length of the queue">queueLength</a>;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         cMessage* wakeup;
<a name="l00199"></a>00199         cMessage* timeout;
<a name="l00200"></a>00200         cMessage* sendData;
<a name="l00201"></a>00201         cMessage* initChecker;
<a name="l00202"></a>00202         cMessage* checkChannel;
<a name="l00203"></a>00203         cMessage* start_lmac;
<a name="l00204"></a>00204         cMessage* send_control;
<a name="l00205"></a>00205 
<a name="l00207"></a><a class="code" href="a00126.html#ab797f8cfd8e9b42c7ca72ed33c4af8d8">00207</a>         <span class="keywordtype">double</span> <a class="code" href="a00126.html#ab797f8cfd8e9b42c7ca72ed33c4af8d8" title="the bit rate at which we transmit">bitrate</a>;
<a name="l00208"></a>00208 
<a name="l00210"></a>00210         <span class="keywordtype">void</span> findNewSlot();
<a name="l00211"></a>00211 
<a name="l00213"></a><a class="code" href="a00126.html#a5631de1b0bad61ff8c6366040cc4681c">00213</a>         <a class="code" href="a00088.html" title="May be published by MAC lyer to indicate why a packet was dropped.">DroppedPacket</a> <a class="code" href="a00126.html#a5631de1b0bad61ff8c6366040cc4681c" title="Inspect reasons for dropped packets.">droppedPacket</a>;
<a name="l00214"></a>00214 
<a name="l00216"></a><a class="code" href="a00126.html#a64482bc131ae8b5598fbf97db66f4552">00216</a>         <span class="keywordtype">int</span> <a class="code" href="a00126.html#a64482bc131ae8b5598fbf97db66f4552" title="publish dropped packets nic wide">nicId</a>;
<a name="l00217"></a>00217 
<a name="l00219"></a>00219         <span class="keywordtype">void</span> attachSignal(macpkt_ptr_t macPkt);
<a name="l00220"></a>00220 
<a name="l00222"></a><a class="code" href="a00126.html#abe6c59398a7e27aa3e421e65690ed6e8">00222</a>         <span class="keywordtype">double</span> <a class="code" href="a00126.html#abe6c59398a7e27aa3e421e65690ed6e8" title="Transmission power of the node.">txPower</a>;
<a name="l00223"></a>00223 
<a name="l00224"></a>00224 };
<a name="l00225"></a>00225 
<a name="l00226"></a>00226 <span class="preprocessor">#endif</span>
<a name="l00227"></a>00227 <span class="preprocessor"></span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>LMacLayer.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
